package org.cbg.panel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import org.cbg.btn.CBGLijigoumaiBtn;
import org.cbg.btn.TrslationBtn;
import org.cbg.entity.Collection;
import org.cbg.frame.TraslationCommodityJFrame;
import org.cbg.frame.TrslationMainJframe;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.CutButtonImage;

import com.tool.btn.FormsOnOffBtn;
import com.tool.tcpimg.UIUtils;



public class TraslationCommodityMainJPane extends JPanel {

    /**
     * 图片 ,物品名,金额,收藏,收藏人数,收藏数字 ,添加好友，下单,立即购买
     */
    private JLabel tupian, wupinming, jine, shoucangrenshu, shoucangshuzi,qmz,bhsm,mjnc,mjid,zdmj,cssysj,gssysj ;
    private TrslationBtn shoucang, tianjiahaoyou;
    private CBGLijigoumaiBtn lijigoumai,lianximaiji;// xiadan,
     private JLabel lijigoumaiLa;// xiadanLa,
    private TraslationCommodityJFrame traslationCommodityJFrame;

    /**
     * 公示期的勾选以及提示文字
     */
    private JLabel quanxuankuang, gouxuan, increaseAmount;

    /**
     * 商品编号 , 卖家昵称, 卖家ID, 指定买家ID, 出售剩余时间,公示剩余时间
     */
    private JTextField number, nickname, sellerID, assignID, sellingtime, publicitytime;

    /**
     * 是否被收藏标识(0表示被收藏，1表示没有被收藏)
     */
    private int stateOrNo = 1;

    public TraslationCommodityMainJPane() {

        /**
         * 面板设置
         */
        this.setPreferredSize(new Dimension(670, 428));
        this.setOpaque(false);
        this.setLayout(null);

        /**
         * 组建初始化
         */
        tupian = new JLabel();
        wupinming = new JLabel("元气丹");
        jine = new JLabel("￥555.00元");
        shoucang = new TrslationBtn("inkImg/number/b4/qxscxx.png", 1);
        shoucangrenshu = new JLabel("44 人收藏");
        tianjiahaoyou = new TrslationBtn("skin/8100226/button/16.png", 1);
        lijigoumai = new CBGLijigoumaiBtn("inkImg/number/b4/lkgmaj.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16,
                "", this);


        lianximaiji = new CBGLijigoumaiBtn("inkImg/number/b4/kbaj.png", 1, UIUtils.COLOR_BTNPUTONG1, UIUtils.TEXT_HY88,
                "联系卖家", this);

        number = new JTextField();
        nickname = new JTextField();
        sellerID = new JTextField();
        assignID = new JTextField();
        sellingtime = new JTextField();
        publicitytime = new JTextField();
        gouxuan = new JLabel();
        quanxuankuang = new JLabel();
//         lijigoumaiLa = new JLabel();
        FormsOnOffBtn guanbi = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 79);
        increaseAmount = new JLabel("<html><body>同意支付<font color='#FF0000' >123121</font>元预定费</body></html>");

        qmz = new JLabel("天界 -大话西游Ⅱ经典版 $Revision: 2309011-");
        bhsm = new JLabel("编号：");
        mjnc = new JLabel("卖家昵称：");
        mjid = new JLabel("卖家ID：");
        zdmj = new JLabel("买家ID：");
        cssysj = new JLabel("出售剩余时间：");
        gssysj = new JLabel("公示剩余时间：");
        /**
         * 组建设置位置和大小
         */
        tupian.setBounds(25, 69, 53, 53);
        wupinming.setBounds(90, 78, 100, 18);
        jine.setBounds(90, 100, 100, 18);

        number.setBounds(183, 47, 100, 18);//编号

        shoucang.setBounds(12 + 2, 392, 28, 28);
        shoucangrenshu.setBounds(10, 400, 85, 18);

        tianjiahaoyou.setBounds(180, 191 - 60, 19, 19);
        // xiadanLa.setBounds(50, 347, 58, 24);
        lijigoumai.setBounds(670 - 100, 428 - 35, 83, 31);
        this.lianximaiji.setBounds(400, 428 - 35, 120, 40);

        nickname.setBounds(80, 192 - 60, 120, 18);
        sellerID.setBounds(70, 216 - 60, 120, 18);
        assignID.setBounds(70, 243 - 60, 120, 18);

        sellingtime.setBounds(148, 268+55, 120, 18);
        publicitytime.setBounds(105, 250, 120, 18);

        guanbi.setBounds(670 - 37 , 10, 25, 25);


        gouxuan.setBounds(22, 293 - 12, 15, 15);
        quanxuankuang.setBounds(22, 293 - 12, 17, 16);
        // xiadan.setBounds(40, 347, 53, 24);
//         lijigoumaiLa.setBounds(154, 347, 100, 25);
        increaseAmount.setBounds(48, 293 - 14, 230, 18);

        qmz.setBounds(20, 45, 100, 18);
        bhsm.setBounds(150, 45, 100, 18);



        mjnc.setBounds(20, 192 - 62, 120, 18);
        mjid.setBounds(20, 216 - 62, 120, 18);
        zdmj.setBounds(20, 243 - 62, 120, 18);

        cssysj.setBounds(45, 268+55, 120, 18);
        gssysj.setBounds(20, 250, 120, 18);

        /**
         * 组件透明化
         */
        tupian.setOpaque(false);
        wupinming.setOpaque(false);
        jine.setOpaque(false);
        shoucang.setOpaque(false);
        shoucangrenshu.setOpaque(false);
        tianjiahaoyou.setOpaque(false);
        lijigoumai.setOpaque(false);
        lianximaiji.setOpaque(false);
        number.setOpaque(false);
        nickname.setOpaque(false);
        sellerID.setOpaque(false);
        assignID.setOpaque(false);
        sellingtime.setOpaque(false);
        publicitytime.setOpaque(false);
        gouxuan.setOpaque(false);
        quanxuankuang.setOpaque(false);
        // xiadan.setOpaque(false);
//         lijigoumaiLa.setOpaque(false);
        increaseAmount.setOpaque(false);

        qmz.setOpaque(false);
        bhsm.setOpaque(false);

        mjnc.setOpaque(false);
        mjid.setOpaque(false);
        zdmj.setOpaque(false);
        cssysj.setOpaque(false);
        gssysj.setOpaque(false);

        /**
         * 组件边框透明化
         */
        lijigoumai.setBorder(null);
        lianximaiji.setBorder(null);
        // xiadan.setBorder(null);
        number.setBorder(null);
        nickname.setBorder(null);
        sellerID.setBorder(null);
        assignID.setBorder(null);
        sellingtime.setBorder(null);
        publicitytime.setBorder(null);
        increaseAmount.setBorder(null);

        /**
         * 组件修改字体
         */
        wupinming.setFont(new Font("宋体", Font.BOLD, 15));
        jine.setFont(new Font("宋体", Font.BOLD, 15));
        number.setFont(UIUtils.TEXT_FONT);

        nickname.setFont(UIUtils.TEXT_FONT1);
        sellerID.setFont(UIUtils.TEXT_FONT1);
        assignID.setFont(UIUtils.TEXT_FONT1);
        sellingtime.setFont(new Font("宋体", Font.BOLD, 14));
        publicitytime.setFont(UIUtils.TEXT_FONT);
        increaseAmount.setFont(UIUtils.TEXT_HY177);

        qmz.setFont(UIUtils.TEXT_FONT);
        bhsm.setFont(UIUtils.TEXT_FONT);

        mjnc.setFont(UIUtils.TEXT_FONT);
        mjid.setFont(UIUtils.TEXT_FONT);
        zdmj.setFont(UIUtils.TEXT_FONT);
        cssysj.setFont(new Font("宋体", Font.BOLD, 14));
        gssysj.setFont(UIUtils.TEXT_FONT);

        /**
         * 组件修改字体颜色
         */
        wupinming.setForeground(UIUtils.COLOR_cbg11);
        jine.setForeground(UIUtils.COLOR_cbg12);
        shoucangrenshu.setForeground(UIUtils.COLOR_cbg5);
        // xiadanLa.setForeground(Color.yellow);
        number.setForeground(UIUtils.COLOR_cbg10);

        nickname.setForeground(UIUtils.COLOR_cbg10);
        sellerID.setForeground(UIUtils.COLOR_cbg10);
        assignID.setForeground(UIUtils.COLOR_cbg10);

        sellingtime.setForeground(UIUtils.COLOR_cbg13);
        publicitytime.setForeground(UIUtils.COLOR_cbg10);
//         lijigoumaiLa.setForeground(Color.yellow);
        increaseAmount.setForeground(new Color(187, 165, 75));

        qmz.setForeground(UIUtils.COLOR_cbg10);
        bhsm.setForeground(UIUtils.COLOR_cbg10);

        mjnc.setForeground(UIUtils.COLOR_cbg10);
        mjid.setForeground(UIUtils.COLOR_cbg10);
        zdmj.setForeground(UIUtils.COLOR_cbg10);
        cssysj.setForeground(UIUtils.COLOR_cbg13);
        gssysj.setForeground(UIUtils.COLOR_cbg10);

        /**
         * 组件设置图片
         */
        gouxuan.setIcon(null);
        quanxuankuang.setIcon(CutButtonImage.getImage("inkImg/number/b4/gxk.png", 17, 16));

        /**
         * 组件设置名字
         */
        gouxuan.setName("1");

        /**
         * 组件设置内容居中
         */
        shoucangrenshu.setHorizontalAlignment(SwingConstants.RIGHT);

        /**
         * 组件设置内容不可修改
         */
        number.setEditable(false);
        nickname.setEditable(false);
        sellerID.setEditable(false);
        assignID.setEditable(false);
        sellingtime.setEditable(false);
        publicitytime.setEditable(false);

        /**
         * 面板添加组件
         */
        this.add(tupian);
        this.add(wupinming);
        this.add(jine);
        this.add(shoucang);
        this.add(shoucangrenshu);
//        this.add(tianjiahaoyou);
        this.add(lijigoumai);
         this.add(lianximaiji);
        this.add(number);
        this.add(nickname);
        this.add(sellerID);
        this.add(assignID);
        this.add(sellingtime);
        this.add(publicitytime);
        this.add(guanbi);
        this.add(gouxuan);
        this.add(quanxuankuang);
        // this.add(xiadanLa);
        // this.add(xiadan);
        this.add(increaseAmount);


        this.add(qmz);
        this.add(bhsm);

        this.add(mjnc);
        this.add(mjid);
        this.add(zdmj);
        this.add(cssysj);
        this.add(gssysj);

        /**
         * 组件设置监听
         */
        shoucang.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                try {
                    if (stateOrNo == 1) {
                        shoucang.setIcons(CutButtonImage.cuts("inkImg/number/b4/qxscxx.png"));
                        stateOrNo = 0;
                    } else {
                        shoucang.setIcons(CutButtonImage.cuts("inkImg/number/b4/scxx.png"));
                        stateOrNo = 1;
                    }
                } catch (Exception e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

                TrslationBtn shoucangBtn = (TrslationBtn) TrslationMainJframe.getTrslationMainJframe().getShoucangBtn();
                shoucangBtn.setIcons(shoucang.getIcons());

                /**
                 * 藏宝阁收藏-取消 1、初始化Collection对象 2、添加角色ID，商品ID 3、根据标识转为对应的json字符串
                 * 4、提交给服务器
                 */
                Collection collection = new Collection();
                // collection.setRoleid(new BigDecimal(sellerID.getText()));
                // collection.setSaleid(new BigDecimal(number.getText()));
                String sendmes = Agreement.getAgreement().searchCollectionAgreement(number.getText());
                SendMessageUntil.toServer(sendmes);
            }
        });

        gouxuan.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                TraslationMyMessageJpanel traslationMyMessageJpanel = TrslationMainJframe.getTrslationMainJframe().getTrslationMainJpanel().getTranslationMainCardJpanel().getTraslationMyMessageJpanel();
                if ("1".equals(gouxuan.getName())) {
                    gouxuan.setIcon(CutButtonImage.getImage("skin/8100226/button/13.png", 15, 15));
                    gouxuan.setName("0");
                    TrslationMainJframe.getTrslationMainJframe().setGoodsGouxuangeshu(
                            TrslationMainJframe.getTrslationMainJframe().getGoodsGouxuangeshu() + 1);
                    if (TrslationMainJframe.getTrslationMainJframe().getGoodsGouxuangeshu() == 10) {
                        traslationMyMessageJpanel.getGouxuan()
                                .setIcon(CutButtonImage.getImage("skin/8100226/button/13.png", -1, -1));
                        traslationMyMessageJpanel.getGouxuan().setName("0");
                    }
                } else {
                    gouxuan.setIcon(null);
                    gouxuan.setName("1");
                    TrslationMainJframe.getTrslationMainJframe().setGoodsGouxuangeshu(
                            TrslationMainJframe.getTrslationMainJframe().getGoodsGouxuangeshu() - 1);
                    if (TrslationMainJframe.getTrslationMainJframe().getGoodsGouxuangeshu() != 10) {
                        traslationMyMessageJpanel.getGouxuan().setIcon(null);
                        traslationMyMessageJpanel.getGouxuan().setName("1");
                    }
                }

            }
        });

    }

    public void setViewTrue(boolean boo) {
        gouxuan.setVisible(boo);
        quanxuankuang.setVisible(boo);
        increaseAmount.setVisible(boo);
    }

    /**
     * 清空面板内容
     */
    public void cleanNeirong() {
        tupian.setIcon(null);
        wupinming.setText("");
        jine.setText("");
        shoucangrenshu.setText("");
        number.setText("");
        nickname.setText("");
        sellerID.setText("");
        assignID.setText("");
        sellingtime.setText("");
        publicitytime.setText("");
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (icon == null) {
            icon = new ImageIcon("inkImg/number/b4/gwjm.png");
        }
        g.drawImage(icon.getImage(), 0, 0, 670, 428, this);


    }

    public JLabel getTupian() {
        return tupian;
    }

    public void setTupian(JLabel tupian) {
        this.tupian = tupian;
    }

    public JLabel getWupinming() {
        return wupinming;
    }

    public void setWupinming(JLabel wupinming) {
        this.wupinming = wupinming;
    }

    public JLabel getJine() {
        return jine;
    }

    public void setJine(JLabel jine) {
        this.jine = jine;
    }

    public JLabel getShoucangrenshu() {
        return shoucangrenshu;
    }

    public void setShoucangrenshu(JLabel shoucangrenshu) {
        this.shoucangrenshu = shoucangrenshu;
    }

    public JLabel getShoucangshuzi() {
        return shoucangshuzi;
    }

    public void setShoucangshuzi(JLabel shoucangshuzi) {
        this.shoucangshuzi = shoucangshuzi;
    }

    public TrslationBtn getShoucang() {
        return shoucang;
    }

    public void setShoucang(TrslationBtn shoucang) {
        this.shoucang = shoucang;
    }

    public TrslationBtn getTianjiahaoyou() {
        return tianjiahaoyou;
    }

    public void setTianjiahaoyou(TrslationBtn tianjiahaoyou) {
        this.tianjiahaoyou = tianjiahaoyou;
    }

    public int getStateOrNo() {
        return stateOrNo;
    }

    public void setStateOrNo(int stateOrNo) {
        this.stateOrNo = stateOrNo;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

    public TraslationCommodityJFrame getTraslationCommodityJFrame() {
        return traslationCommodityJFrame;
    }

    public void setTraslationCommodityJFrame(TraslationCommodityJFrame traslationCommodityJFrame) {
        this.traslationCommodityJFrame = traslationCommodityJFrame;
    }

    public JTextField getNumber() {
        return number;
    }

    public void setNumber(JTextField number) {
        this.number = number;
    }

    public JTextField getNickname() {
        return nickname;
    }

    public void setNickname(JTextField nickname) {
        this.nickname = nickname;
    }

    public JTextField getSellerID() {
        return sellerID;
    }

    public void setSellerID(JTextField sellerID) {
        this.sellerID = sellerID;
    }

    public JTextField getAssignID() {
        return assignID;
    }

    public void setAssignID(JTextField assignID) {
        this.assignID = assignID;
    }

    public JTextField getSellingtime() {
        return sellingtime;
    }

    public void setSellingtime(JTextField sellingtime) {
        this.sellingtime = sellingtime;
    }

    public JTextField getPublicitytime() {
        return publicitytime;
    }

    public void setPublicitytime(JTextField publicitytime) {
        this.publicitytime = publicitytime;
    }

    public CBGLijigoumaiBtn getLijigoumai() {
        return lijigoumai;
    }

    public void setLijigoumai(CBGLijigoumaiBtn lijigoumai) {
        this.lijigoumai = lijigoumai;
    }

    public JLabel getQuanxuankuang() {
        return quanxuankuang;
    }

    public void setQuanxuankuang(JLabel quanxuankuang) {
        this.quanxuankuang = quanxuankuang;
    }

    public JLabel getGouxuan() {
        return gouxuan;
    }

    public void setGouxuan(JLabel gouxuan) {
        this.gouxuan = gouxuan;
    }

    public JLabel getIncreaseAmount() {
        return increaseAmount;
    }

    public void setIncreaseAmount(JLabel increaseAmount) {
        this.increaseAmount = increaseAmount;
    }

}
